﻿using CardMaker.Library.Services;
using System.IO;
using System.Linq.Expressions;
using System.Text.Encodings.Web;
using System.Text.Json;

namespace CardMaker.Library.Models; 

public class CreateCard {
    private CardTemplate _template;
    private List<SideImage> _sideImage;
    private List<TextFrame> _textFrame;
    private CardTemplate _cardTemplate = new();
    private CardTemplate card = new();
    
    private readonly ICardTemplateService _cardTemplateService;
    private readonly ISideImageStorage _sideImageStorage;
    private readonly ICardTemplateStorage _cardTemplateStorage;
    private readonly IPreferenceStorage _preferenceStorage;

    public CreateCard(IPreferenceStorage preferenceStorage,
        ICardTemplateService cardTemplateService, ICardTemplateStorage cardTemplateStorage, ISideImageStorage sideImageStorage)
    {
        _preferenceStorage = preferenceStorage;
        _cardTemplateService = cardTemplateService;
        _cardTemplateStorage = cardTemplateStorage;
        _sideImageStorage = sideImageStorage;
    }

    public Task<CardTemplate> GetCardTemplateAsync(int id)
    {
        return _cardTemplateService.GetCardTemplateAsync(id);
    }
    public async Task<List<SideImage>> GetSideImagesAsync(int cardTemplateId)
    {

        return this._sideImage=(List<SideImage>) await _sideImageStorage.GetSideImagesAsync(cardTemplateId);
    }

    public async Task<IEnumerable<CardTemplate>> GetCardTemplatesAsync()
    {
        return await _cardTemplateService.GetCardTemplatesAsync();
    }
    public Task SaveCardTemplateAsync(CardTemplate cardTemplate, List<SideImage> sideImages, List<TextFrame> textFrames)
    {
        return _cardTemplateService.AddCardTemplateAsync(
            cardTemplate, sideImages, textFrames);
    }
    
}